<extend name="Public/base"/>

<block name="style">
    <style>
        .hero-unit h1{
            font-size: 45px;
            margin-bottom: 45px
        }
        .hero-unit p{
            line-height: 1.8em;
            margin-top: 15px;
        }
        .hero-unit .btn-group{
            margin:35px 0;
        }

        .previewBox{margin:0 2%;width: 320px}
        .ArticlePreviewBox{width: 100%;min-height: 80px;border: 1px solid #eee; padding: 10px}
        .firstArticle{}
        .otherArticle{margin-top:5px;padding: 5px;border-top: 1px solid #ddd}
        .coverImage {height:9em;overflow:hidden}
        .coverImage img{ width:100%;}
        .firstTitle{bottom:0;right:0;left:0;height: 3em;padding:5px;background:rgba(0,0,0,0.6)!important;font-size: 1em;color:#fff}
        .firstTitle span {line-height: 1em}
        .itemTitle {width: 79%}
        .indexImage {width: 19%}
        .indexImage img {width: 100%}
        .options{margin:15px}
    </style>
</block>
<block name="body">

    <if condition="empty($_list)">
        <div class="container">
            <div class="row">
                <div class="hero-unit">
                    <h1>抱歉，暂时没有图文素材</h1>
                    <p>您可以在下面新增图文素材，或者从微信导入</p>

                    <p class="btn-group">
                        <a href="{:U('WechatMaterial/online',array('type'=>'news'))}" class="btn btn-success btn-large">从微信导入</a>
                        <a href="{:U('addNews')}"  class="btn btn-primary btn-large">新增图文素材</a>
                    </p>
                </div>
            </div>
        </div>
        <else />
        <div class="cf">
            <div class="fl">
                <a class="btn btn-primary" href="{:U('addNews')}">新增本地图文素材</a>
                <a class="btn btn-primary" href="{:U('WechatMaterial/online',array('type'=>'news'))}">从微信服务器下载素材</a>
            </div>
        </div>
        <div class="cf">
        <volist name="_list" id="vo">

            <div class="fl previewBox">
                <div class="ArticlePreviewBox">
                    <foreach name="vo.articles" key="k" item="item">
                        <eq name="item['sort']" value="0">
                            <div class="firstArticle">
                                <div class="coverImage">
                                    <img src="{$item.cover_id|get_cover='path'}">
                                </div>
                                <div class="firstTitle">
                                    <span>{$item.title}</span>
                                </div>
                            </div>
                            <else />
                            <div class="cf otherArticle">
                                <div class="fl itemTitle">
                                    {$item.title}
                                </div>
                                <div class="fr indexImage">
                                    <img src="{$item.cover_id|get_cover='path'}">
                                </div>
                            </div>
                        </eq>
                    </foreach>
                </div>
                <div class="options btn-group">
                    <a class="btn btn-warning confirm ajax-get" href="{:U('deleteNews',array('id'=>$vo['id']))}">删除</a>
                    <a class="btn btn-primary editNews" href="{:U('editNews',array('id'=>$vo['id']))}">编辑</a>
                    <eq name="vo.status" value="1">
                        <a href="#massPreviewModal" class="btn btn-default previewMeterial" role="button" data-id="{$vo.media_id}" data-type="mpnews" data-toggle="modal">预览</a>
                        <a href="#massMessageModal" class="btn btn-danger massMeterial" role="button" data-id="{$vo.media_id}" data-type="mpnews"  data-toggle="modal">群发</a>
                        <else />
                        <span data-id="{$vo.id}" class="btn btn-danger uploadNews">上传</span>
                    </eq>
                </div>
            </div>

        </volist>

        </div>
    </if>

    <!-- 分页 -->
    <div class="cf page">
        {$_page}
    </div>

    <include file="WechatMass/massjs" />
</block>

<block name="script">
    <script>
        $(".uploadNews").click(function(){
            var media_id = $(this).attr('data-id');
            $.post("{:U('uploadNews')}",
                    {'id':media_id},
                    function(re){
                        if(re.status == 1){
                            showInfo(re.info+re.local_id,'alert-success');
                        }else{
                            showInfo(re.info);
                        }
                        location.reload();
                    }
            );
        });

        //弹出提示信息
        function showInfo(info,c){
            c = c || 'alert-error';
            updateAlert(info,c);
            setTimeout(function(){
                $('#top-alert').find('button').click();
            },1500);
        }
    </script>
</block>